<template>
	<view class="feedback_wrap">
		<form @submit="formSubmit">
			<radio-group @change="radioChange">
				<label class="radio" v-for="(item, index) in list" :key="item.id">
					<radio :value="item.id + ''" :checked="item.checked" />{{ item.text }}
				</label>
			</radio-group>
			<textarea v-model="queryInfo.content" maxlength="500" placeholder="请填写具体内容帮助我们了解您的意见和建议" />
			<input v-model="queryInfo.qq" maxlength="15" type="number" placeholder="请填写您的QQ" />
			<input v-model="queryInfo.weixin" maxlength="25" type="text" placeholder="请填写您的微信" />
			<!-- #ifdef APP-PLUS --> 
			<view class="location">
				<view>您当前的位置是: </view>
				<text>{{ location || '获取信息中...' }}</text>
			</view>
			<!-- #endif -->
			<button form-type="submit" :disabled="loading" :loading="loading">提交</button>
		</form>
	</view>
</template>

<script>
	import {
		MyModel
	} from "../../common/apis/my.js"
	const myModel = new MyModel()

	export default {
		data() {	
			return {
				list: [{
						id: 1,
						text: '内容建议',
						checked: true
					},
					{
						id: 2,
						text: '产品建议',
						checked: false
					},
					{
						id: 3,
						text: '其他',
						checked: false
					},
				],
				queryInfo: {
					type: 1,
					content: '',
					qq: '',
					weixin: ''
				},
				location: '',
				loading: false
			};
		},
		onLoad(){
			// 获取位置 仅APP
			// #ifdef APP-PLUS
			uni.getLocation({ 
				geocode: true,
				success: (res) => {
					// #ifdef APP-PLUS
					this.location = `${res.address.country} ${res.address.province} ${res.address.city} ${res.address.district} ${res.address.street} ${res.address.streetNum} ${res.address.poiName} ${res.address.cityCode}`
					// #endif
				}
			})
			// #endif
		},
		methods: {
			// 单选
			radioChange(event) {
				this.queryInfo.type = event.detail.value
			},
			// 表单提交
			async formSubmit() {
				if (!this.queryInfo.content || this.queryInfo.content.length < 10) {
					this.$util.msg('反馈内容至少输入10个字')
					return
				}
				if (!this.queryInfo.qq && !this.queryInfo.weixin) {
					this.$util.msg('QQ和微信至少填写一个')
					return
				}
				if (this.queryInfo.qq && !this.$util.checkStr(this.queryInfo.qq, 'QQ')) {
					this.$util.msg('QQ填写有误')
					return
				}
				if (this.queryInfo.weixin && !this.$util.checkStr(this.queryInfo.weixin, 'weixin')) {
					this.$util.msg('微信填写有误')
					return
				}
				this.loading = true
				uni.showLoading({
					title: '提交中',
					mask: true
				})
				const res = await myModel.sendFeedback(this.queryInfo)
				this.loading = false
				uni.hideLoading()
				uni.showModal({
					content: '您的意见反馈成功!',
					showCancel: false,
					success: () => {
						this.navBack()
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.feedback_wrap {
		padding: 0 30rpx;
	}

	radio-group {
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding: 40rpx 0;
		font-size: 30rpx;

		/deep/.uni-radio-input {
			width: 32rpx;
			height: 32rpx;
		}
	}

	textarea {
		width: 100%;
		height: 300rpx;
		border: 1rpx solid #ddd;
		padding: 20rpx;
	}

	input {
		height: 70rpx;
		padding: 0 10rpx;
		border: 1rpx solid #ddd;
		margin: 30rpx 0;
	}

	.location {
		margin: 50rpx 0;
		font-size: 30rpx;
		color: $mxg-text-color-grey;
		line-height: 50rpx;

		text {
			color: $mxg-text-color-black;
		}
	}

	button {
		background-color: $mxg-text-color-blue;
		color: #fff;
		margin-top: 50rpx
	}
</style>
